package com.briup.jz.service.impl;

import com.briup.jz.bean.ArticleExample;
import com.briup.jz.bean.BaseUser;

import com.briup.jz.bean.BaseUserExample;
import com.briup.jz.bean.extend.BaseUserExtend;
import com.briup.jz.dao.BaseUserMapper;
import com.briup.jz.dao.extend.BaseUserExtendMapper;
import com.briup.jz.service.IUserService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class UserServiceImpl implements IUserService {

    @Resource
    private BaseUserMapper userMapper;

    @Resource
    private BaseUserExtendMapper userExtendMapper;

    @Override
    public List<BaseUser> findAll() {
        return userMapper.selectByExample(new BaseUserExample());
    }

    @Override
    public void saveOrUpdate(BaseUser user) {
        if (user.getId()!=null){
            userMapper.updateByPrimaryKey(user);
        }else {
            userMapper.insert(user);
        }
    }

    @Override
    public void deleteById(long id) {
        userMapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<BaseUserExtend> findAllWithRole() {
        return userExtendMapper.selectAllWithRole();
    }

    @Override
    public BaseUser findById(long id) {
        return userMapper.selectByPrimaryKey(id);
    }

	@Override
	public List<BaseUser> query(String realName, String status) {
		// TODO Auto-generated method stub
		//模板查询
		BaseUserExample example = new BaseUserExample();
		//条件
		BaseUserExample.Criteria criteria = example.createCriteria();//模板对象
		if(realName != null) {
			criteria.andRealnameLike("%"+realName+"%"); //模糊查询
		}
		if(status != null) {
			criteria.andStatusEqualTo(status); //准确字段查询
		}
		return userMapper.selectByExample(example);
	}


}
